package com.trevor.action;

import java.util.ArrayList;
import java.util.HashMap;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.trevor.domain.User;
import com.trevor.services.InformService;

public class BodyAction extends Action {

	@Override
	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		User user=(User)request.getSession().getAttribute("user");
		InformService is=new InformService();
		String position=(String) request.getSession().getAttribute("position");
		HashMap<String, ArrayList> infos=is.getInformation(user, position);
		String a=request.getParameter("select");
		if(a==null){
			a="comments";
		}
		if(a.equals("anounces")){
			ArrayList anounces=infos.get("anounces");
			request.getSession().setAttribute("anounces", anounces);
			return mapping.findForward("anounces");
		}else if(a.equals("comments")){
			ArrayList comments=infos.get("comments");
			request.getSession().setAttribute("comments", comments);
			return mapping.findForward("comments");
		}else if(a.equals("datas")){
			ArrayList datas=infos.get("datas");
			request.getSession().setAttribute("datas", datas);
			return mapping.findForward("datas");
		}else{
			return mapping.findForward("anounces");
		}
	}

}
